package lab02.test23;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/**
 * Created by 婷婷 on 2017/11/1.
 */
public class CalculateBirthday {
    public static void main(String[] args) throws ParseException {
        CalculateBirthday calculateBirthday = new CalculateBirthday();

        Scanner in = new Scanner(System.in);
        System.out.println("输入出生年份：");
        String year = in.next();
        System.out.println("输入出生月份：");
        String month = in.next();
        System.out.println("输入出生月份中的某一天：");
        String day = in.next();

        int birthdayRestTime = calculateBirthday.printBirthdayRestTime(year,month, day);
        calculateBirthday.printBirthdayInWeek(birthdayRestTime);
    }


    private int printBirthdayRestTime(String year, String mouth, String day) throws ParseException {
        Date currentDate = new Date();

        SimpleDateFormat fmt = new SimpleDateFormat("dd MM yyyy");
        Date inputDate = fmt.parse(day + " " + mouth + " " + year);
        int birthdayRestTime = 0;
        if (inputDate.getMonth() < currentDate.getMonth()) {
            birthdayRestTime = 365 - (int) ((currentDate.getTime() - inputDate.getTime()) / 3600 / 24 / 1000)%365;
        } else {
            birthdayRestTime =(int) ((inputDate.getTime() - currentDate.getTime()) / 3600 / 24 / 1000);
        }
        System.out.println("你还有" + birthdayRestTime + "天过生日!\n");
        return birthdayRestTime;
    }


    private void printBirthdayInWeek(int birthdayRestTime) throws ParseException {

        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        int todayOfWeek = cal.get(Calendar.DAY_OF_WEEK);

        int birthdayofWeek = (todayOfWeek + birthdayRestTime % 7) % 7;
        String dayOfWeek = "";
        switch (birthdayofWeek) {
            case 1:
                dayOfWeek = "周日";
                break;
            case 2:
                dayOfWeek = "周一";
                break;
            case 3:
                dayOfWeek = "周二";
                break;
            case 4:
                dayOfWeek = "周三";
                break;
            case 5:
                dayOfWeek = "周四";
                break;
            case 6:
                dayOfWeek = "周五";
                break;
            case 7:
                dayOfWeek = "周六";
                break;
            default:
                break;

        }
        System.out.println("你过生日是：" + dayOfWeek);
    }
}
